home *** CD-ROM | disk | FTP | other *** search
- /*
- * ***************
- * * X R F 3 . C *
- * ***************
- *
- * Sorted cross reference listing routines. 'prtree' performs an
- * inorder traversal of the id tree, printing the references to'
- * each id while visting that node.
- *
- * Version V1.3 9-May-80
- * Version V1.4 10-Jul-80 MM Bummed code, added 80 col. support
- * Version V1.5 2-Dec-84 MC Tweak for CI86 on Msdos Rainbow
- * 7-Jan-85 MC Remove case sensitive printing order
- * Version V1.17 5-Apr-85 MC Add possibility if disk merge.
- */
-
- #include <stdio.h>
- #include "xrf.h"
-
- static char lk[KEYSIZE+1]; /* used for key compare */
- static char *bp; /* buffer pointer */
- static int rcntr; /* refs on line counter */
- static char keyname[9]; /* program name for this symbol */
- static struct BUFR *t;
- extern struct BUFR *wrmatch();
-
-
- printree(link)
- struct idt *link;
- { struct dsk *tr;
- totalprint("M Phase ",lintot,namtot,reftot); /* verbosity */
- lintot=namtot=reftot=0;
- newpage(); /* new page */
- wrfix(polroot); /* fix mdn fchain in place */
- setmem(lk,KEYSIZE,0xFF);
- bp=scanbf;
- rcntr=0;
- setmem(lastsym,'\0',CPS+1);
- prtree(link); /* Print the index */
- setmem(link->keyp,KEYSIZE,0xFF); /* use as scratch area */
- link->first=-1;
- while((t=wrmatch(polroot,link,link->first))!=NULL)
- putref(t->b_key,t->b_ref,scanbf); /* ensure disk files exhausted */
- *bp = '\0'; /* Terminate with null */
- lstrefs(); /* Write the line out */
- wrkill(); /* kill chain */
- if((polroot=polcurr=wropen(wfilno=1))==NULL)/* open 1st file now as there*/
- abort("XRF3 can't open work disk\n"); /* won't be room when needed */
- }
-
- /*
- * Inorder tree traversal.
- */
-
- prtree(link)
- struct idt *link;
- {
- if (link != NULL){
- prtree(link->left); /* Visit the left */
- prtrefs(link); /* Print refs for this one */
- prtree(link->right); /* Visit the right */
- }
- }
-
- /*
- * List out a line of references.
- * Start new page if it gets full.
- */
-
- lstrefs()
- {
- if(++linpg > MAXLIN) /* New page if necessary */
- nwpage();
- fputs(scanbf, lst); /* Write out the string */
- fputs("\n", lst);
- rcntr = 0; /* Reset refs-on-line count */
- }
-
- /*
- * Print id and references.
- * Share scan buffer for printout.
- * Use newpag.
- *
- * The ref line number field width is hard-wired into the format statement.
- * Trouble is, #define's don't (and shouldn't!) substitute into strings,
- * like formats.
- *
- * Current values are 5 char field (RSIZE) and rperline ref's per line.
- *
- * The node is now positioned in the tree in case non-sensitive order.
- * This means that in the final list mixed, upper & lower case symbols
- * appear togethor instead of being separated in the collating sequence.
- *
- * The id (*kp) now comes as <KEYactualNNNNNNNN> from XRF0.C where:-
- * KEY is the symbol as lower case
- * length CPS characters.
- * actual is the symbol as she appears
- * length CPS characters.
- * NNNNNNNN is the program name
- * length 8 chars
- * Be aware that this is now a merge function in case memory disk files
- * are present.
- */
-
- prtrefs(link)
- struct idt *link;
- { struct ref *r = link->first; /* Ref chain pointer */
- do{ /* Process Reference line numbers */
- if((t=wrmatch(polroot,link,r))==NULL){
- putref(link->keyp,r->lno,scanbf); /* process memory */
- r = r->next; /* (On down the chain) */
- }
- else {
- putref(t->b_key,t->b_ref,scanbf); /* else process this one */
- }
- } while(r != NULL); /* Until the end */
- }
-
- static putref(nk,ref,p) /* build reference line */
- char *nk; /* nk --> key */
- int ref; /* reference */
- char *p; /* p --> start of scan buffer */
- { int i;
- if(strcmp(nk,lk)){ /* if key hange ... */
- if(rcntr){ /* if any residue ... */
- *bp = '\0'; /* Terminate with null */
- lstrefs(); /* Write it out */
- bp=p; /* reset buffer pointer */
- rcntr = 0; /* Reset refs-on-line count */
- }
- strcpy(lk,nk);
- rcntr = 0; /* Init refs-per-line */
- strcpy(keyname,nk+CPS+CPS); /* Pull out Program Name */
- if(strncmp(nk+CPS,lastsym,CPS)){ /* if Symbol changed ... */
- strncpy(bp,nk+CPS,CPS); /* put the id string */
- bp += CPS;
- strncpy(lastsym,nk+CPS,CPS); /* save as previous */
- lastsym[CPS]=EOS;
- }
- while(bp < &scanbf[CPS])*bp++ = ' '; /* Pad with blanks */
- *bp++ = ':'; /* Followed by a separator */
- if(conflg){ /* Followed by progname */
- for(i=0;i<8;*bp++=keyname[i++]);
- *bp++ = ' '; /* Followed by a space */
- }
- }
- if(rcntr >= rperline){ /* If this line is full */
- *bp = '\0'; /* Terminate with null */
- lstrefs(); /* Write it out */
- rcntr = 0; /* Reset refs-on-line count */
- for(bp=scanbf;bp<&scanbf[CPS];*bp++ =' '); /*Reset buffer ptr*/
- *bp++ = ':'; /* plus a separator */
- if(conflg){ /* Followed by progname */
- for(i=0;i<8;*bp++=keyname[i++]);
- *bp++ = ' '; /* Followed by a space */
- }
- }
- rcntr++;
- sprintf(bp,"%5d", ref); /* Insert ref into buffer */
- bp += RSIZE; /* Update buffer pointer */
- }